package com.ztgf.shopping.scheduled;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.commodity.models.dto.BrandInfoDTO;
import com.ztgf.commodity.models.service.IBrandInfoService;
import com.ztgf.commodity.models.service.ICommodityInfoService;
import com.ztgf.common.utils.CustomizeUtil;
import com.ztgf.common.utils.DateUtils;
import com.ztgf.message.model.bo.MessageAnnouncementSaveBO;
import com.ztgf.message.model.constant.MessageTopicType;
import com.ztgf.message.model.dto.ResponseDTO;
import com.ztgf.message.model.enums.MessageEnum;
import com.ztgf.message.model.service.IKafkaProducerService;
import com.ztgf.order.models.dto.OrderCommodityRelationDTO;
import com.ztgf.order.models.dto.OrderInfoDTO;
import com.ztgf.order.models.dto.OrderStatusDTO;
import com.ztgf.order.models.dto.purchase.PurchaseInfoDTO;
import com.ztgf.order.models.service.IOrderCommodityRelationService;
import com.ztgf.order.models.service.IOrderInfoService;
import com.ztgf.order.models.service.IOrderStatusService;
import com.ztgf.order.models.service.purchase.IPurchaseCommodityBargainService;
import com.ztgf.order.models.service.purchase.IPurchaseInfoService;
import com.ztgf.search.models.service.IShopSearchService;
import com.ztgf.shopping.common.config.YmlConfig;
import com.ztgf.shopping.models.constant.ShoppingConstant;
import com.ztgf.shopping.models.dto.shop.*;
import com.ztgf.shopping.models.enums.ShoppingCodeEnum;
import com.ztgf.shopping.models.service.shop.*;
import com.ztgf.shopping.models.vo.shop.ShopImResponseVO;
import com.ztgf.sms.models.bo.SmsInfoSaveBO;
import com.ztgf.sms.models.service.ISmsInfoService;
import com.ztgf.sys.models.dto.SysDictDTO;
import com.ztgf.sys.models.service.ISysDictService;
import com.ztgf.user.models.dto.UserLoginDTO;
import com.ztgf.user.models.service.IUserLoginService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/01/26 14:10
 */
@Component
@Slf4j
public class ScheduledTimes {
    @DubboReference
    private IShopQualificationService iShopQualificationService;
    @DubboReference
    private IShopInfoService iShopInfoService;
    @DubboReference
    private IBrandInfoService iBrandInfoService;
    @DubboReference
    private IKafkaProducerService kafkaProducerService;
    @DubboReference
    private ICommodityInfoService iCommodityInfoService;
    @DubboReference
    private ISysDictService iSysDictService;
    @DubboReference
    private IUserLoginService iUserLoginService;
    @DubboReference
    private ISmsInfoService iSmsInfoService;
    @DubboReference
    private IShopContractSettleInService shopContractSettleInService;
    @DubboReference
    private IShopQiyuesuoInfoService shopQiyuesuoInfoService;
    @DubboReference
    private IShopEarnestMoneyService iShopEarnestMoneyService;
    @DubboReference
    private IShopSearchService shopSearchService;
    @DubboReference
    private IShopOnlineService shopOnlineService;
    @DubboReference
    private IShopSysInvoiceService shopSysInvoiceService;
    @DubboReference
    private IPurchaseCommodityBargainService iPurchaseCommodityBargainService;
    @DubboReference
    private IOrderCommodityRelationService iOrderCommodityRelationService;
    @DubboReference
    private IOrderInfoService orderInfoService;
    @DubboReference
    private IPurchaseInfoService purchaseInfoService;
    @DubboReference
    private IOrderStatusService orderStatusService;
    @Resource
    private YmlConfig ymlConfig;

    /**
     * 每天凌晨执行一次 更新企业资质过期状态
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void executeUpdateQualificationExpire() throws Exception {
        try {
            boolean flag = true;
            Long minNo = 0L;
            Integer PageNo = 50;
            do {
                List<ShopQualificationDTO> dtos = iShopQualificationService.queryExpire(minNo, PageNo);
                if (dtos != null && dtos.size() > 0) {
                    if (dtos.size() < PageNo) {
                        flag = false;
                    }
                    for (ShopQualificationDTO dto : dtos) {
                        minNo = dto.getId();
                        if (DateUtils.getCurrentDate().compareTo(dto.getEndDate()) >= 0) {
                            //已经过期，更新资质状态
                            updateQualification(dto, 2);
                            addSms(dto.getShopId());
                            //若是基础资质，冻结店铺。若是品牌资质，下架所有品牌
                            if (dto.getType() <= 2) {
                                frozenShop(dto.getShopId());
                            } else {
                                if (dto.getType()==3){
                                    EntityWrapper<ShopQualificationDTO> wrapper = new EntityWrapper<>();
                                    wrapper.eq("shop_id",dto.getShopId());
                                    wrapper.eq("type",4);
                                    ShopQualificationDTO shopQualificationDTOS = iShopQualificationService.selectOne(wrapper);
                                    if (shopQualificationDTOS!=null){
                                        if (DateUtils.getCurrentDate().compareTo(shopQualificationDTOS.getEndDate()) >= 0) {
                                            publish(dto.getShopId(), dto.getBrandId());
                                        }
                                    }
                                }else {
                                    publish(dto.getShopId(), dto.getBrandId());
                                }

                            }
                        }
                    }
                } else {
                    flag = false;
                }

            } while (flag);
            log.info("--------------定时任务：更新企业资质过期状态 ------------------");
        } catch (Exception e) {
            log.error("定时任务：更新企业资质过期状态异常", e);
        }
    }


    /**
     * 每10分钟更新入驻合同信息
     */
    @Scheduled(cron = "0 0/10 * * * ?")
    public void executeUpdate() {
        log.info("--------------定时任务：入驻状态合同检测开始 ------------------");
        boolean isSelect = true;
        Long lastNo = 0L;
        do {
            List<ShopContractSettleInDTO> shopContractSettleInDTOList = shopContractSettleInService.getNotSignContact(lastNo);
            if (shopContractSettleInDTOList.size() < 50) {
                isSelect = false;
            }
            for (ShopContractSettleInDTO shopContractSettleInDTO : shopContractSettleInDTOList) {
                lastNo = shopContractSettleInDTO.getShopId();
                boolean b = false;//
                try {
                    b = shopQiyuesuoInfoService.getSignContactState(Long.parseLong(shopContractSettleInDTO.getContractLockId()), 2);
                } catch (NumberFormatException e) {
                    log.error("此店铺id：" + lastNo + "获取入驻状态合同失败");
                    e.printStackTrace();
                }
                if (b) {
                    shopContractSettleInDTO.setStartDate(new Date());
                    shopContractSettleInDTO.setEndDate(DateUtils.addYear(new Date(), 1));
                    shopContractSettleInDTO.setId(shopContractSettleInDTO.getId());
                    shopContractSettleInDTO.setStatus(1);//0未签订，1已签订
                    shopContractSettleInService.updateById(shopContractSettleInDTO);

                    //修改店铺信息表
                    ShopInfoDTO shopInfoDTO = new ShopInfoDTO();
                    shopInfoDTO.setId(shopContractSettleInDTO.getShopId());
                    shopInfoDTO.setCheckAgreementStatus(1);//入住协议签订状态 0未签订，1已签订
                    iShopInfoService.updateById(shopInfoDTO);
                }
            }
        } while (isSelect);

        log.info("--------------定时任务：入驻状态合同检测结束 ------------------");
    }

    /**
     * 每天凌晨一点执行一次 更新企业资质即将到期状态
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void executeUpdateQualificationBeforExpire() {
        try {
            boolean flag = true;
            Long minNo = 0L;
            Integer PageNo = 50;
            do {
                List<ShopQualificationDTO> dtos = iShopQualificationService.queryBeforExpire(minNo, PageNo);
                if (dtos != null && dtos.size() > 0) {
                    if (dtos.size() < PageNo) {
                        flag = false;
                    }
                    SysDictDTO sysDictDTO = iSysDictService.getByName(ShoppingConstant.QUALIFICATION_EXPIRE_TIME);//资质快到期时间提醒
                    String time = sysDictDTO.getValue();
                    Date expireTime = DateUtils.addDay(DateUtils.getCurrentDate(), Integer.valueOf(time));
                    for (ShopQualificationDTO dto : dtos) {
                        minNo = dto.getId();
                        if (expireTime.compareTo(dto.getEndDate()) >= 0) {
                            //若快过期，更新资质状态
                            updateQualification(dto, 1);
                            urgeSignContact("您的部分资质30天后即将到期。", dto.getShopId());
                        }
                    }
                } else {
                    flag = false;
                }
            } while (flag);
            log.info("--------------定时任务：更新企业资质即将到期状态 ------------------");
        } catch (Exception e) {
            log.error("定时任务：更新企业资质即将到期状态", e);
        }
    }

    /**
     * 每天凌晨1点执行一次 更新关店检测
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void executeUpdateCloseStatusExpire() {
        try {
            boolean flag = true;
            Long minNo = 0L;
            Integer PageNo = 50;
            do {
                List<ShopInfoDTO> dtos = iShopInfoService.queryCloseStatus(minNo, 50);
                if (dtos != null && dtos.size() > 0) {
                    if (dtos.size() < PageNo) {
                        flag = false;
                    }
                    SysDictDTO sysDictDTO = iSysDictService.getByName(ShoppingConstant.CLOSE_SHOP_TIME);//资质快到期时间提醒
                    String time = sysDictDTO.getValue();
                    for (ShopInfoDTO dto : dtos) {
                        minNo = dto.getId();
                        //检测
                        boolean flagclose = iShopInfoService.getVerifyCloseShop(dto.getId());
                        if (flagclose) {
                            //若没有订单，则进入下一阶段
                            /**
                             * 1. 改变状态
                             * 2. 增加关店时间
                             */
                            ShopInfoDTO shopInfoDTO = new ShopInfoDTO();
                            shopInfoDTO.setId(dto.getId());
                            shopInfoDTO.setCloseStatus(2);
                            shopInfoDTO.setCloseTime(DateUtils.addDay(DateUtils.getCurrentDateTime(), Integer.parseInt(time)));
                            iShopInfoService.updateById(shopInfoDTO);
                        }
                    }
                } else {
                    flag = false;
                }
            }
            while (flag);
            log.info("--------------定时任务：更新关店检测订单是否有未完成的 ------------------");
        } catch (Exception e) {
            log.error("定时任务：更新关店检测订单是否有未完成的", e);
        }
    }

    /**
     * 每天凌晨2点执行一次 更新关店
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void executeUpdateCloseShopExpire() {
        try {
            boolean flag = true;
            Long minNo = 0L;
            Integer PageNo = 50;
            do {
                List<ShopInfoDTO> dtos = iShopInfoService.queryCloseShop(minNo, PageNo);
                if (dtos != null && dtos.size() > 0) {
                    if (dtos.size() < PageNo) {
                        flag = false;
                    }
                    Long now_m = System.currentTimeMillis(); //获取当前时间毫秒数
                    for (ShopInfoDTO dto : dtos) {
                        minNo = dto.getId();
                        //判断时间
                        Long now_s = dto.getCloseTime().getTime(); //获取关店毫秒数
                        if (now_s < now_m) {
                            //超时
                            ShopInfoDTO shopInfoDTO = new ShopInfoDTO();
                            shopInfoDTO.setId(dto.getId());
                            shopInfoDTO.setMarginStatus(3);//保证金状态 0未缴纳，1已缴纳，2保证金不足 ,3退还
                            shopInfoDTO.setCloseStatus(3);//关店流程状态 0未开启，1检测中（检测订单）.2关店中（关店倒计时中）.3已关店
                            shopInfoDTO.setFrozenStatus(2);//冻结状态 0未冻结，1冻结 2关店
                            shopInfoDTO.setAdminFrozenStatus(2);//管理员冻结状态 0未冻结，1冻结 2关店
                            iShopInfoService.updateById(shopInfoDTO);

                            //发起退还保证金
                            iShopEarnestMoneyService.updateReturnMoney(dto.getId());
                        }
                    }
                } else {
                    flag = false;
                }
            } while (flag);
            log.info("--------------定时任务：更新关店状态 ------------------");
        } catch (Exception e) {
            log.error("定时任务：更新关店状态", e);
        }
    }

    //更新资质过期状态
    private void updateQualification(ShopQualificationDTO dto, Integer status) {
        ShopQualificationDTO shopQualificationDTO = new ShopQualificationDTO();
        BeanUtils.copyProperties(dto, shopQualificationDTO);
        shopQualificationDTO.setExpireStatus(status);//到期状态 0正常，1即将到期，2已过期
        iShopQualificationService.updateById(shopQualificationDTO);
    }

    //冻结店铺
    private void frozenShop(Long id) {
        ShopInfoDTO shopInfoDTO = new ShopInfoDTO();
        shopInfoDTO.setId(id);
        shopInfoDTO.setFrozenStatus(1);//冻结状态 0未冻结，1冻结 2关店
        iShopInfoService.updateById(shopInfoDTO);
        // TODO 自动冻结移除店铺ES
        shopSearchService.deleteData("index_shop_2020", "shop", id.toString());
        urgeSignContact("您的基础资质已到期。", shopInfoDTO.getId());
    }

    //下架某店铺某品牌商品
    private void publish(Long shopId, Long brandId) {
        BrandInfoDTO brandInfoDTO = iBrandInfoService.selectById(brandId);

        iCommodityInfoService.updateBatchPublishByShopBrand(shopId, brandId);
        String conunt = "您的店铺下的品牌: " + brandInfoDTO.getName() + " 的相关资质已过期, 该品牌下的所有商品已自动下架，请及时处理。";
        urgeSignContact(conunt, shopId);
    }

    //发送站内信
    private void urgeSignContact(String conunt, Long shopId) {
        MessageAnnouncementSaveBO messageAnnouncementSaveBO = new MessageAnnouncementSaveBO();
        ShopInfoDTO shopInfoDTO = iShopInfoService.selectById(shopId);
        if (shopInfoDTO == null) {
            return;
        }
        Integer shopType = iShopInfoService.selectById(shopId).getMerchantType();

        if (shopType.equals(ShoppingCodeEnum.MERCHANT_BUYER.getCode())) {
            //买家
            messageAnnouncementSaveBO.setShopType(MessageEnum.SHOP_TYPE_1.getCode());
        } else {
            messageAnnouncementSaveBO.setShopType(MessageEnum.SHOP_TYPE_2.getCode());
        }

        ResponseDTO responseDTO = new ResponseDTO();
        messageAnnouncementSaveBO.setContent(conunt);
        messageAnnouncementSaveBO.setShopId(shopId);
        messageAnnouncementSaveBO.setType(MessageEnum.SYS_MESSAGE.getCode());
        messageAnnouncementSaveBO.setTitle("资质到期提醒");
        messageAnnouncementSaveBO.setJumpType(MessageEnum.MESSAGE_SHOW.getCode() + "");
        messageAnnouncementSaveBO.setTextType(1);
        messageAnnouncementSaveBO.setKey(shopId + "");
        responseDTO.setData(messageAnnouncementSaveBO);
        responseDTO.setMessageId(shopId + "");
        kafkaProducerService.senMessage(JSON.toJSONString(responseDTO), MessageTopicType.COMMENT_MESSAGE_TOPIC);
    }

    private void addSms(Long shopId) {
        Wrapper<UserLoginDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("user_id", iShopInfoService.selectById(shopId).getUserId());

        SmsInfoSaveBO bo = new SmsInfoSaveBO();

        bo.setMobile(iUserLoginService.selectOne(wrapper).getMobile());
        try {
            iSmsInfoService.saveQualificationExpired(bo);
        } catch (Exception e) {
            log.info(e.toString());
        }
    }

    /**
     * @return : void
     * @Author :chenyu.wang
     * @Description : 每分钟检测卖家是否离线
     * @Date : 11:34 2021.01.12
     * @Param : []
     **/
    @Scheduled(cron = "0 0/1 * * * ?")
    public void checkShopOnlineOut() {
        log.info("--------------定时任务：检查用户是否退出登录开始 ------------------");
        try {
            boolean flag = true;
            Long lastNo = 0L;
            Date nowDate = new Date();
            do {
                List<ShopOnlineDTO> list = shopOnlineService.queryDayNotOutList(lastNo);
                if (list != null && list.size() > 0) {
                    if (list.size() < 50) {
                        flag = false;
                    }
                    for (ShopOnlineDTO dto : list) {
                        lastNo = dto.getId();
                        // 查询店铺im状态
                        ShopImResponseVO responseVO = shopOnlineService.getShopImState(dto.getShopId());
                        log.info("定时任务查询店铺IM状态响应信息:{}", responseVO);
                        // 响应状态为1时代表失败或者有报错信息
                        Integer responseValue = responseVO.getResponseValue();
                        if (responseValue.equals(1) || !responseValue.equals(200)) {
                            continue;
                        }
                        Integer code = responseVO.getCode();
                        if (!code.equals(200)) {
                            continue;
                        }
                        String status = responseVO.getStatus();
                        if ("true".equals(status)) {
                            continue;
                        }
                        long start = dto.getCreateTime().getTime();
                        long end = nowDate.getTime();
                        long min = (end - start) / (1000 * 60);
                        // 修改退出时间
                        ShopOnlineDTO updateDto = new ShopOnlineDTO();
                        updateDto.setOutTime(nowDate);
                        updateDto.setId(dto.getId());
                        updateDto.setDuration(min);
                        updateDto.setIsOnline(0);
                        updateDto.setUpdateTime(nowDate);
                        shopOnlineService.updateById(updateDto);
                    }
                } else {
                    flag = false;
                }

            } while (flag);
            log.info("--------------定时任务：检查用户是否退出登录结束 ------------------");
        } catch (Exception e) {
            log.error("定时任务：检查用户是否退出登录错误信息:{}", e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * @return : void
     * @Author :chenyu.wang
     * @Description : 每天凌晨检查店铺变更时间是否到期，到期后将变更状态改为初始值
     * @Date : 2021.01.27 14:20
     * @Param : []
     **/
    @Scheduled(cron = "0 59 23 * * ?")
    public void checkShopChangeState() {
        log.info("--------------定时任务：检查店铺变更时间是否到期开始 ------------------");
        try {
            boolean flag = true;
            Long lastNo = 0L;
            Date nowDate = new Date();
            do {
                Page<ShopInfoDTO> page = new Page<>(0, 50);
                Wrapper<ShopInfoDTO> wrapper = new EntityWrapper<>();
                wrapper.gt("id", lastNo);
                wrapper.orderBy("id", true);
                Page<ShopInfoDTO> selectPage = iShopInfoService.selectPage(page, wrapper);
                List<ShopInfoDTO> list = selectPage.getRecords();
                if (CustomizeUtil.listIsNotNull(list)) {
                    if (list.size() < 50) {
                        flag = false;
                    }
                    for (ShopInfoDTO dto : list) {
                        lastNo = dto.getId();
                        if (dto.getChangeTime() == null) {
                            continue;
                        }
                        // 获取一年后的时间
                        Date oneYearTime = CustomizeUtil.getOneYearTime(dto.getChangeTime());
                        if (nowDate.before(oneYearTime)) {
                            continue;
                        }
                        iShopInfoService.updateChangeTime(dto.getId());
                    }
                } else {
                    flag = false;
                }

            } while (flag);
            log.info("--------------定时任务：检查店铺变更时间是否到期结束 ------------------");
        } catch (Exception e) {
            log.info("定时任务：检查店铺变更时间是否到期错误信息:{}", e.getMessage());
            e.printStackTrace();
        }
    }

    /**
     * @return : void
     * @Author :liyang
     * @Description : 每分钟检测同步平台开票列表数据
     **/
    @Scheduled(cron = "0 0/1 * * * ?")
    public void synchronizationShopSysInvoice() {
        //同步固定申请平台砍价固定费率29.8（买家）
//        -----------------------------废弃方法--------------------------------
//        List<ShopSysInvoiceDTO> shopSysInvoiceDTOS = new ArrayList<>();
//        shopSysInvoiceDTOS = iPurchaseCommodityBargainService.synchronizationShopSysInvoice();
//        if (CustomizeUtil.listIsNotNull (shopSysInvoiceDTOS)){
//            List<PurchaseCommodityBargainDTO> purchaseCommodityBargainDTOS = new ArrayList<>();
//            for (ShopSysInvoiceDTO dto : shopSysInvoiceDTOS){
//                dto.setId (ymlConfig.getPkId ());
//                dto.setType (2); //类型 0物流费，1佣金，2砍价固定技术服务费，3砍价佣金
//                dto.setName ("技术服务费");
//                dto.setStatus (1); //开票状态 0已开票，1未开票
//                dto.setSellOrBuyType (0); //状态：0买家，1卖家
//                boolean flag = shopSysInvoiceService.insert (dto);
//                if (flag){
//                    PurchaseCommodityBargainDTO purchaseCommodityBargainDTO = new PurchaseCommodityBargainDTO ();
//                    purchaseCommodityBargainDTO.setId (dto.getPurchaseCommodityBargainId ());
//                    purchaseCommodityBargainDTO.setSynchronizationShopSysInvoiceType (1); //同步平台砍价技术服务费状态：0未同步，1已同步
//                    purchaseCommodityBargainDTOS.add (purchaseCommodityBargainDTO);
//                }
//            }
//            iPurchaseCommodityBargainService.updateBatchById (purchaseCommodityBargainDTOS);
//        }
//        -----------------------------废弃方法--------------------------------
        List<ShopSysInvoiceDTO> shopSysInvoiceDTOS = new ArrayList<>();
        shopSysInvoiceDTOS = purchaseInfoService.getSynchronizationShopSysInvoiceBuy();
        if(CustomizeUtil.listIsNotNull (shopSysInvoiceDTOS)){
            List<PurchaseInfoDTO> purchaseInfoDTOS = new ArrayList<>();
            for (ShopSysInvoiceDTO dto : shopSysInvoiceDTOS) {
                dto.setId (ymlConfig.getPkId ());
                dto.setType (2); //类型 0物流费，1佣金，2砍价固定技术服务费，3砍价佣金
                dto.setName ("信息系统增值服务");
                dto.setStatus (1); //开票状态 0已开票，1未开票
                dto.setSellOrBuyType (0); //状态：0买家，1卖家
                boolean flag = shopSysInvoiceService.insert (dto);
                if (flag) {
                    PurchaseInfoDTO purchaseInfoDTO = new PurchaseInfoDTO ();
                    purchaseInfoDTO.setId (dto.getPurchaseId ());
                    purchaseInfoDTO.setSynchronizationShopSysInvoiceType (1); //同步平台砍价技术服务费状态：0未同步，1已同步
                    purchaseInfoDTOS.add(purchaseInfoDTO);
                }
            }
            purchaseInfoService.updateBatchById (purchaseInfoDTOS);
        }


        //同步技术服务费（卖家）
        List<ShopSysInvoiceDTO> vosSell = new ArrayList<>();
        vosSell = iOrderCommodityRelationService.synchronizationShopSysInvoiceSell();
        if(CustomizeUtil.listIsNotNull (vosSell)){
            List<OrderInfoDTO> orderInfoDTOS = new ArrayList<>();
            for (ShopSysInvoiceDTO dto : vosSell){
                dto.setId (ymlConfig.getPkId ());
                dto.setType (1); //类型 0物流费，1佣金，2砍价固定技术服务费，3砍价佣金
                dto.setName ("信息系统增值服务");
                dto.setStatus (1); //开票状态 0已开票，1未开票
                dto.setSellOrBuyType (1); //状态：0买家，1卖家
                boolean flag = shopSysInvoiceService.insert (dto);
                if (flag){
                    OrderInfoDTO orderInfoDTO = new OrderInfoDTO ();
                    orderInfoDTO.setId (dto.getOrderId ());
                    orderInfoDTO.setSynchronizationShopSysInvoiceType (1);//同步平台开票技术服务费：0未同步，1已同步
                    orderInfoDTOS.add(orderInfoDTO);
                }
            }
            orderInfoService.updateBatchById (orderInfoDTOS);
        }

        //同步技术服务费（买家申请平台砍价成功）

//        -----------------------------废弃方法--------------------------------

//        List<ShopSysInvoiceDTO> vosBuy = new ArrayList<>();
//        vosBuy = iOrderCommodityRelationService.synchronizationShopSysInvoiceBuy();
//        if(CustomizeUtil.listIsNotNull (vosBuy)) {
//            List<OrderCommodityRelationDTO> orderCommodityRelationDTOS1 = new ArrayList<>();
//            for (ShopSysInvoiceDTO dto : vosBuy) {
//                dto.setId (ymlConfig.getPkId ());
//                dto.setType (3); //类型 0物流费，1佣金，2砍价固定技术服务费，3砍价佣金
//                dto.setName ("技术服务费");
//                dto.setStatus (1); //开票状态 0已开票，1未开票
//                dto.setSellOrBuyType (0); //状态：0买家，1卖家
//                boolean flag = shopSysInvoiceService.insert (dto);
//                if (flag) {
//                    OrderCommodityRelationDTO commodityRelationDTO = new OrderCommodityRelationDTO ();
//                    commodityRelationDTO.setId (dto.getOrderCommodityRelationId ());
//                    commodityRelationDTO.setSynchronizationShopSysInvoiceType (1); //同步平台开票技术服务费：0未同步，1已同步
//                    orderCommodityRelationDTOS1.add (commodityRelationDTO);
//                }
//            }
//            iOrderCommodityRelationService.updateBatchById (orderCommodityRelationDTOS1);
//        }

//        -----------------------------废弃方法--------------------------------

        List<ShopSysInvoiceDTO> vosBuy = new ArrayList<>();
        vosBuy = orderStatusService.getSynchronizationShopSysInvoiceBuy();
        if(CustomizeUtil.listIsNotNull (vosBuy)) {
            List<OrderStatusDTO> orderStatusDTOS = new ArrayList<>();
            List<OrderCommodityRelationDTO> orderCommodityRelationDTOS1 = new ArrayList<>();
            for (ShopSysInvoiceDTO dto : vosBuy) {
                dto.setId (ymlConfig.getPkId ());
                dto.setType (3); //类型 0物流费，1佣金，2砍价固定技术服务费，3砍价佣金
                dto.setName ("信息系统增值服务");
                dto.setStatus (1); //开票状态 0已开票，1未开票
                dto.setSellOrBuyType (0); //状态：0买家，1卖家
                boolean flag = shopSysInvoiceService.insert (dto);
                if (flag) {
                    OrderStatusDTO orderStatusDTO = new OrderStatusDTO ();
                    orderStatusDTO.setId (dto.getOrderStatusId ());
                    orderStatusDTO.setSynchronizationShopSysInvoiceType (1);//同步平台开票技术服务费：0未同步，1已同步
                    orderStatusDTOS.add(orderStatusDTO);
                }
            }
            orderStatusService.updateBatchById (orderStatusDTOS);
        }

    }





}
